package CollectIteratorDemo;

import java.util.*;

public class CollectArrayDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("11A");
        list.add("22B");
        list.add("33C");
        System.out.println("--------====-------");
        System.out.println("--------==降序==-------");

        list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return  o2.compareTo(o1);

            }
        });
        //用循环遍历
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("---------------");
        //用增强for循环遍历
        for (String s : list) {
            System.out.println(s);
            System.out.println("-------z增强for--------");
        }
        //用LambDa的表达式forEach遍历
        list.forEach(System.out::println);
        System.out.println("--------forEach-------");
        //用迭代器遍历
        Iterator it = list.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
            System.out.println("---------------");
        }

    }
}
